# -*- coding: utf-8 -*-
"""
Created on Thu Aug 17 16:07:06 2023

@author: skunk69
"""

import json

chinese_name = u'中学生二维自尊量表（修订版）'
english_name = 'Self-Liking/Self-Competence Scale Revised for Middle School Students'
abbreviation = 'SLCS-R'
category = u'自我意识与自尊量表'

outline = u"""自尊是人们对自身价值的总体评价，包括信念和情感，并体现在行为中，是尊严的个体内在成分。自尊研究经历了强调价值因素或胜任力因素的单一研究到将两者整合研究的过程。前者以Rosenberg为代表，并开发了Rosenberg自尊量表RSES。后者以Tafarodi和Swann的二维自尊研究为代表，认为自尊包括对自己的价值性（自我悦纳，Self-Liking，SL）和工具性（自我胜任，Self-Competence，SC）评价两个不同的方面，并在此基础上编制了二维自尊量表（Self-Liking/self-Competence Scale, SLCS）。随后又对原量表进行了修订，形成了包括两个维度、各8个条目、条目正反向各半的二维自尊量表修订版SLCS-R。
国内韦嘉等人（2012）在获得Tafarodi教授的授权后，基于中学生群体对SLCS-R进行了本土化修订。中文版SLCS-R保留了原量表的结构，替换了部分测量学特性不佳的条目，信效度检验表明，中文版SLCS-R是测量中学生群体二维自尊水平的可靠有效工具。"""

instruction = u"""下面的条目均是涉及您本人情况的一些描述。请评估这些描述跟您真实情况的符合程度或者正确程度，并在每个条目表述后相应的选项中选择最适合的一项。所有条目都请进行评估。"""

with open('SLCS-R.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    f.close()

items = {}
for key,line in enumerate(lines):
    _,value = line.strip().split('）',maxsplit=1)
    items[key+1] = value

reverse_items = [1,6,7,8,10,13,15,16]
scales = [u'自我悦纳',u'自我胜任']
scales_items = [
    [1,3,5,6,7,9,11,15],
    [2,4,8,10,12,13,14,16],
    ]

# check scales_items
print(f'scale length={[len(l) for l in scales_items]}')

check = []
for l in scales_items:
    check = check+l
print(f'len(check)={len(check)}')

# complementary set
check_set = {i for i in sorted(check)}^{i for i in range(1,17)}
print(f'complementary set= {check_set}')

factors = []
factors_scales = []
rating = [u'非常不符合',u'比较不符合',u'中间状态',u'比较符合',u'非常符合']
score_rules = list(range(1,6))

contents = {
    'instruction':instruction,
    'items':items,
    'reverse_items':reverse_items,
    'scales':scales,
    'scales_items':scales_items,
    'factors':factors,
    'factors_scales':factors_scales,
    'rating':rating,
    'score_rules':score_rules       
    }

implementation = u"""《中学生二维自尊量表（修订版）》属于自评量表。"""

reliability = u"""所报告的信效度指标是采用方便抽样方法从初高中群体中获得。总量表的Cronbach α系数为0.85，SL和SC的α系数分别为0.79和0.75。总量表间隔四周重测组内相关绝对一致性系数为0.8，SL和SC两个分量表分别为0.76和0.73。"""
validity = u"""在上述样本中随机抽取20%进行验证性因素分析。聚合效度检验发现SLCS-R的维度分与总分同Rosenberg自尊量表RSES的相关达到了0.5~0.67的显著正相关水平。"""
measurements = {'reliability':reliability,'validity':validity}

interpretation = u"""首先将反向题目反向计分，然后将各维度题目相加得到各维度分，所有条目之和得到总分。总分越高说明被测者自尊水平越高。"""

applications = u"""无常模。"""

this_scale = {
    'chinese_name':chinese_name,
    'english_name':english_name,
    'abbreviation':abbreviation,
    'category':category,
    'outline':outline,
    'contents':contents,
    'implementation':implementation,
    'measurements':measurements,
    'interpretation':interpretation,
    'applications':applications    
    }

with open(abbreviation+'.json','w+',encoding='utf-8') as f:
    json.dump(this_scale,f,indent=2,ensure_ascii=False)